home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / archivers / xpk / xpk_source / xpkmaster / progress.c < prev    next >
C/C++ Source or Header  |  1999-06-14  |  2KB  |  79 lines

  1. #ifndef XPKMASTER_PROGRESS_C
  2. #define XPKMASTER_PROGRESS_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        progress.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: progress.c 1.5 (12.03.1999)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Progress report handler
  12.  
  13.  1.0   06.10.96 : first real version
  14.  1.1   24.03.97 : added auto hook, changed speed calculation
  15.  1.2   25.04.97 : changed time calculation
  16.  1.3   09.01.98 : added XPK_ALLINONE
  17.  1.4   26.03.98 : a bit shorter exe code
  18.  1.5   12.03.99 : fixed factor calculation for large files
  19. */
  20.  
  21. #include <proto/exec.h>
  22. #include <proto/intuition.h>
  23. #include <xpk/xpkprefs.h>
  24. #include "xpkmaster.h"
  25.  
  26. XPK_ALLINONE LONG callprogress(struct XpkBuffer *xbuf)
  27. {
  28.   struct XpkProgress *prog = &xbuf->xb_Prog;
  29.   struct Hook *hk = xbuf->xb_ChunkHook;
  30.   struct XpkPrefsSemaphore *sem = 0;
  31.  
  32.   if(!hk && (xbuf->xb_Flags & XMF_AUTOPRHOOK) && (sem = GetPrefsSem()))
  33.     hk = sem->xps_ProgressHook;
  34.  
  35.   if(hk)
  36.   {
  37.     ULONG ucur, ulen;
  38.  
  39.     if((ucur = prog->xp_UCur) && (ulen = prog->xp_ULen))
  40.     {
  41.       ULONG secs;
  42.       LONG mics;
  43.  
  44.       CurrentTime (&secs, (ULONG *) &mics);
  45.       secs -= xbuf->xb_Secs;
  46.       mics -= xbuf->xb_Mics;
  47.  
  48.       /* 7813 = 100000 / 128, 0x1000000 = 0x100000000/256 (ULONG size),
  49.          +1 prevents division by zero */
  50.       if(ucur < 0x1000000)
  51.         prog->xp_Speed = (ucur<<7) / ((secs<<7) + mics/7813 + 1);
  52.       else
  53.         prog->xp_Speed = ucur / ++secs;
  54.  
  55.       if(ucur > 0x01FFFFFF)
  56.     prog->xp_Done = ucur / (ulen / 100);
  57.       else
  58.         prog->xp_Done = 100 * ucur / ulen;
  59.  
  60.       if(prog->xp_CCur > 0x01FFFFFF)
  61.         prog->xp_CF = 100 - prog->xp_CCur / (ucur / 100);
  62.       else
  63.         prog->xp_CF = 100 - 100 * prog->xp_CCur / ucur;
  64.     }
  65.     if(prog->xp_CF < 0)
  66.       prog->xp_CF = 0;
  67.  
  68.     if((*(regfunc) hk->h_Entry) (hk, prog, 0 A4SUPP2))
  69.       xbuf->xb_Result = XPKERR_ABORTED;
  70.   }
  71.  
  72.   if(sem)
  73.     ReleaseSemaphore((struct SignalSemaphore *) sem);
  74.  
  75.   return xbuf->xb_Result;
  76. }
  77.  
  78. #endif /* XPKMASTER_PROGRESS_C */
  79.